//
//  MagazineHistoryViewController.m
//  JianChaRiBao
//
//  Created by Changxy on 13-7-31.
//  Copyright (c) 2013年 wzyk. All rights reserved.
//

#import "MagazineHistoryViewController.h"
#import "MagazineHistotyCell.h"
#import "MagazineInfoViewController.h"
@interface MagazineHistoryViewController ()

@end

@implementation MagazineHistoryViewController
- (IBAction)backButtonClicked:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        shouldSwipeBack = YES;
    }
    return self;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.mDataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * cellID = @"cellID";
    MagazineHistotyCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MagezineHistory" owner:self options:nil]lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell getCellWithDict:[self.mDataArray objectAtIndex:indexPath.row]];
    return cell;
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80.0f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MagazineInfoViewController * magazineInfo = [[MagazineInfoViewController alloc]initWithNibName:@"MagazineInfoViewController" bundle:nil];
    magazineInfo.basicInfo = [self.mDataArray objectAtIndex:indexPath.row];
    magazineInfo.pushFromHistory = YES;
    [self.navigationController pushViewController:magazineInfo animated:YES];
    [magazineInfo release];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.mDataArray = [NSMutableArray arrayWithCapacity:0];
    titleLabel.text = [self.mDict objectForKey:@"magazinename"];
    [self getData];
}

-(void)getData{
    id obj = [[DataRequest sharedRequest] getHistoryInfo:[self.mDict objectForKey:@"catalogid"]];
//    NSLog(@"obj:%@",obj);
    if ([obj isKindOfClass:[NSDictionary class]]) {
        [self.mDataArray addObjectsFromArray:[obj objectForKey:@"result"]];
    }

    [mTableView reloadData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [titleLabel release];
    [mTableView release];
    [super dealloc];
}
- (void)viewDidUnload {
    [titleLabel release];
    titleLabel = nil;
    [mTableView release];
    mTableView = nil;
    [super viewDidUnload];
}
@end
